package com.zhuiYun.project.api.commoditydetail.controller;

import com.zhuiYun.project.api.commoditydetail.entity.UserHistory;
import com.zhuiYun.project.api.commoditydetail.service.CommodityDetailService;
import com.zhuiYun.project.common.controller.BaseController;
import com.zhuiYun.project.common.errorCode.CommonException;
import com.zhuiYun.project.common.response.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName CommodityDetailController
 * @Description TODO
 * @Author 赵笛
 * @Date 2023/4/4 15:52
 **/
@RestController
@RequestMapping("/commodity/detail/")
@Api(tags = "商品详情管理")
@Slf4j
@CrossOrigin
public class CommodityDetailController extends BaseController {
    @Autowired
    CommodityDetailService commodityDetailService;
    /**
    * @Author 赵笛
    * @Description TODO 根据id查询当前商品
    * @Date 2023/4/4 16:45
    * @Return com.zhuiYun.project.common.response.CommonResult
    * @param commodityId
    */
    @GetMapping("/getCommodityById")
    @ApiOperation(value = "商品详情的查询方法")
    public CommonResult getCommodityById(Integer commodityId){
        log.info("根据id查询当前商品");
        return commodityDetailService.getCommodityById(commodityId);
    }
    /**
     * @Author 赵笛
     * @Description TODO 根据商品id查询当前商品规格
     * @Date 2023/4/5 8:59
     * @Return com.zhuiYun.project.common.response.CommonResult
     * @param commodityId
     */
    @GetMapping("/getCommoditySpecById")
    @ApiOperation(value = "根据商品id查询当前商品规格的方法")
    public CommonResult getCommoditySpecById(Integer commodityId){
        log.info("根据商品id查询当前商品规格");
        return commodityDetailService.getCommoditySpecById(commodityId);
    }

    /**
    * @Author 赵笛
    * @Description TODO getCommentByCommodityId
    * @Date 2023/4/5 12:46
    * @Return com.zhuiYun.project.common.response.CommonResult
    * @param commodityId
    */
    @GetMapping("/getCommentByCommodityId")
    @ApiOperation(value = "根据商品id查询评论的方法")
    public CommonResult getCommentByCommodityId(Integer commodityId){
        log.info("根据商品id查询评论的方法");
        return commodityDetailService.getCommentByCommodityId(commodityId);
    }

    /**
    * @Author 赵笛
    * @Description TODO 根据用户id查询收货地址
    * @Date 2023/4/6 11:09
    * @Return com.zhuiYun.project.common.response.CommonResult
    * @param userId
    */
    @GetMapping("getAddressList")
    @ApiOperation(value = "根据用户id查询收货地址的方法")
    public CommonResult getAddressList(Integer userId) throws CommonException {
        log.info("根据用户id查询收货地址");
        return commodityDetailService.getAddressList(userId);
    }
    /**
     * @Description 根据商品ids获取商品信息列表
     * @Author lzy
     * @Date 2023/4/5 19:56
     * @Return com.zhuiYun.project.common.response.CommonResult
     * @param ids
     */
    @GetMapping("/getCommodityListByIds")
    @ApiOperation(value = "根据商品ids获取商品信息列表")
    public CommonResult getCommodityListByIds(String ids) throws CommonException {
        return commodityDetailService.getCommodityListByIds(ids);
    }
    /**
    * @Author sgo
    * @Description
    * @Date 2023/4/13 15:29
    * @Return
    * @param ids
    */
    @GetMapping("/getCommodDIYityListByIds")
    @ApiOperation(value = "根据DIy商品商品ids获取商品信息列表")
    public CommonResult getCommodDIYityListByIds(String ids) throws CommonException {
        return commodityDetailService.getCommodDIYityListByIds(ids);
    }
    /**
    * @Author 赵笛
    * @Description TODO
    * @Date 2023/4/6 16:03
    * @Return com.zhuiYun.project.common.response.CommonResult
    * @param addressId
    */
    @GetMapping("/getAddressById")
    @ApiOperation(value = "根据地址id获取地址信息")
    public CommonResult getAddressById(Integer addressId) throws CommonException {
        log.info("根据地址id获取地址信息");
        return commodityDetailService.getAddressById(addressId);
    }
    /**
    * @Author 赵笛
    * @Description TODO 根据用户id查询当前用户收藏的商品列表
    * @Date 2023/4/11 14:06
    * @Return com.zhuiYun.project.common.response.CommonResult
    * @param userId
    * @param commodityName
    */
    @GetMapping("/getCommodityCollectionListByUserId")
    @ApiOperation(value = "根据用户id查询当前用户收藏的商品列表")
    public CommonResult getCommodityCollectionListByUserId(Integer userId,String commodityName) throws CommonException {
        log.info("根据用户id查询当前用户收藏的商品列表");
        return commodityDetailService.getCommodityCollectionListByUserId(userId,commodityName);
    }
    /**
    * @Author 赵笛
    * @Description TODO 保存用户浏览历史
    * @Date 2023/4/11 19:09
    * @Return com.zhuiYun.project.common.response.CommonResult
    * @param userHistory
    */
    @PostMapping("/saveUserHistory")
    @ApiOperation(value = "保存用户浏览历史")
    public CommonResult saveUserHistory(@RequestBody UserHistory userHistory){
        log.info("保存用户浏览历史");
        return commodityDetailService.saveUserHistory(userHistory);
    }

    /**
     * @Author 赵笛
     * @Description TODO 根据当前用户查找浏览记录
     * @Date 2023/4/11 14:06
     * @Return com.zhuiYun.project.common.response.CommonResult
     * @param userId
     * @param itemType
     */
    @GetMapping("/getUserHistoryByUserId")
    @ApiOperation(value = "根据当前用户查找浏览记录")
    public CommonResult getUserHistoryByUserId(Integer userId,Integer itemType) throws CommonException {
        log.info("根据当前用户查找浏览记录");
        return commodityDetailService.getUserHistoryByUserId(userId,itemType);
    }
    /**
    * @Author 赵笛
    * @Description TODO 删除历史记录
    * @Date 2023/4/18 9:56
    * @Return com.zhuiYun.project.common.response.CommonResult
    * @param commodityId
    * @param userId
    * @param itemType
    */
    @DeleteMapping("/deleteHistory")
    @ApiOperation(value = "删除历史记录")
    public CommonResult deleteHistory(Integer commodityId,Integer userId,Integer itemType) throws CommonException {
        log.info("删除历史记录");
        return commodityDetailService.deleteHistory(commodityId,userId,itemType);
    }

}
